<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
      <!-- 用户搜索 -->
      <el-form-item label="分账接收方名称" prop="userName" label-width="120">
        <el-input v-model="queryParams.receiverName" placeholder="请输入用户" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      <el-button icon="Refresh" @click="resetQuery">重置</el-button>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain  @click="handleExport"
          v-hasPermi="['admin:withdrawRecord:export']">新增分账接收方</el-button>
      </el-col>
      <!-- <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="withdrawRecordList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="分账接收方名称" width="120" align="center" prop="receiverName" />
      <el-table-column label="联系手机号" align="center" prop="contactMobile" />
      <el-table-column label="对公对私" align="center" prop="acctTypeCode" />
      <el-table-column label="营业执照号码" align="center" prop="licenseNo" />
      <el-table-column label="营业执照名称" align="center" prop="licenseName" />
      <el-table-column label="法人姓名" align="center" prop="legalPersonName" />
      <el-table-column label="法人证件类型" align="center" prop="legalPersonCertificateType" />
      <el-table-column label="法人证件号" align="center" prop="legalPersonCertificateNo" />
      <el-table-column label="收款账户卡号" align="center" prop="acctNo" />
      <el-table-column label="收款账户名称" align="center" prop="acctName" />
      <el-table-column label="收款账户证件类型" align="center" prop="acctCertificateType" />
      <el-table-column label="收款账户证件号" align="center" prop="acctCertificateNo" />
      <el-table-column label="收款账户开户行号" align="center" prop="acctOpenBankCode" />
      <el-table-column label="收款账户开户名称" align="center" prop="acctOpenBankName" />
      <el-table-column label="收款账户清算行行号" align="center" prop="acctClearBankCode" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleAudit(scope.row)"
            v-hasPermi="['admin:withdrawRecord:edit']" v-if="scope.row.verifyState == 0">审核</el-button>
        </template>
</el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script setup name="WithdrawRecord">
import { listWithdrawRecord } from "@/api/money/recipientList";
import { listMoney } from "@/api/money/money";
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";

const { proxy } = getCurrentInstance();

const withdrawRecordList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const router = useRouter();
const open = ref(false);
const statisticsData = ref('--');
const route = useRoute();

const verifyList = ref([
  {
    label: "未审核",
    value: 0
  },
  {
    label: "审核通过",
    value: 1
  },
  {
    label: "审核不通过",
    value: 2
  }
])

const verifyRemarkRule = (rule, value, callback) => {
  if (form.value.verifyState == 0) {
    if (!value) {
      return callback(new Error('请输入审核不通过原因!'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    moneyId: null,
    withdrawAmount: null,
    withdrawWay: null,
    bankCard: null,
    cardNo: null,
    realName: null,
    mobile: null,
    serviceCharge: null,
    realAmount: null,
    paymentAmount: null,
    status: null,
    verifyState: null,
    verifyBy: null,
    verifyTime: null,
    withdrawType: route.query.withdrawType,
  },
  form: {},
  rules: {
    verifyState: [
      {
        require: true,
        message: "请选择审核状态!",
        trigger: 'change',
      }
    ],
    verifyRemark: [
      {
        validator: verifyRemarkRule,
        trigger: 'change',
      }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);

/**
 * 获取货币列表
 */
const moneyList = ref([]);
function getMoneyList() {
  listMoney().then(response => {
    moneyList.value = response.rows;
  });
}
getMoneyList();



/** 查询提现记录列表 */
function getList() {
  loading.value = true;
  listWithdrawRecord(queryParams.value).then(response => {
    console.log("🚀🚀🚀 ~ listWithdrawRecord ~ response:", response)
    withdrawRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });

}

function handleAudit(item) {
  form.value = {
    id: item.id,
    verifyState: 0,
    verifyRemark: '',
  }
  console.log(form.value, 'form')
  open.value = true
}

function submitForm() {
  proxy.$refs["forms"].validate(valid => {
    if (valid) {

    }
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}


/** 导出按钮操作 */
function handleExport() {
  router.push({
    path: "/mall/addLedger",
  });
}

getList();
</script>
